﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="CentalineWeb.Login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>登录</title>
    <link href="/Styles/login.css" rel="stylesheet" type="text/css" />
    <link href="/Styles/jquery_css/jquery.ui.core.css" rel="stylesheet" type="text/css" />
    <link href="/Styles/jquery_css/jquery.ui.theme.css" rel="stylesheet" type="text/css" />
    <link href="/Styles/jquery_ui/redmond/jquery-ui-1.10.2.custom.min.css" rel="stylesheet"
        type="text/css" />
    <script src="/Scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="/Scripts/easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-ui-1.10.2.custom.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.cookie.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.json-2.3.min.js" type="text/javascript"></script>
    <script src="/Scripts/Window.js" type="text/javascript"></script>
    <script src="/Scripts/Common.js" type="text/javascript"></script>
    <script src="/Scripts/jqUtil.js" type="text/javascript"></script>
    <script type="text/javascript">
        var errMsg = '<%=ErrorMessage %>';
        var alertID = "";
        function userLogin() {
            var userName = $("#txtUserAccount").val();
            var userPass = $("#txtUserPassword").val();

            if (userName.length < 1) { alertID = jqAlert("请输入用户名", function () { alertID = ""; }); return false; }
            if (userPass.length < 1) { alertID = jqAlert("请输入密码", function () { alertID = ""; }); return false; }
            if (userPass.length < 6) { alertID = jqAlert("密码长度小于6位", function () { alertID = ""; }); return false; }
            if (userPass.length > 100) { alertID = jqAlert("密码长度过长", function () { alertID = ""; }); return false; }

            var vURL = "/Server/Login.aspx?Action=CheckLogin";
            if ($("#admin").attr("checked") == "checked") {
                vURL += "&isAdmin=true";
            }
            alertID = "1";
            submitJSONForm(vURL, 'frmLogin',
                           function (d) {
                               alertID = "";
                               //写入cookie
                               if ($("#rember_me").attr("checked") == "checked") {
                                   var username = $("#txtUserAccount").val();
                                   var password = $("#txtUserPassword").val();
                                   $.cookie("username", username, { expires: 7 });
                                   $.cookie("password", password, { expires: 7 });
                               }
                               window.location.href = "mysheet.aspx"; 
                           }
                       , null, null, function () { alertID = ""; });
        }

        function winLogin() {
            $('#frmLogin').submit();
        }

        $(function () {

            //是否有cookie
            if ($.cookie("username") && $.cookie("password")) {
                $("#txtUserAccount").val($.cookie("username"));
                $("#txtUserPassword").val($.cookie("password"));
            }
        });
        $(function () {
            $("#txtUserAccount").focus();
            $(document).keyup(function (evt) {
                if (evt.keyCode == 13) {
                    if (alertID == "") $("#loginBtn").click();
                }
            });

            if ("" != errMsg) {
                jqAlert(errMsg);
            }
        });
    </script>
</head>
<body>
    <form id="frmLogin" action="WinLogin.aspx">
    <div style="position: absolute;top: 60%;left: 50%;">
        <table width="350px" border="0" cellspacing="0" cellpadding="0" >
            <tr>
                 <td>
                     用户名：
                </td>
                <td>
                        <input name="txtUserAccount" type="text" class="userInput" value="" id="txtUserAccount" />
                </td>
            </tr>
            <tr>
                 <td>
                       密码：
                </td>
                <td>
                        <input name="txtUserPassword" type="password" class="userInput" value="" id="txtUserPassword" />
                </td>
            </tr>
           <tr>
                   <td colspan="2" style="font-size: 12px;">
                       <input id="rember_me" type="checkbox" checked="checked" />一周内自动登录
                       <input id="admin" type="checkbox"  />管理员登录
                   </td> 
           </tr>
            <tr>
                <td  height="48"  colspan="2">
                    <input name="button2" type="button" id="loginBtn" class="btn" onclick="userLogin();" value="登录" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
